﻿var fn = {
    //使用$.request替换该方法
    queryStr: function (name) {
        return $.request(name);
    },
    setQueryStr: function (url, name, qstr) {
        if (qstr) {
            var qv = $.request(name, url);
            var qparam = name + "=" + qstr;
            if (qv) {
                return url.replace(name + "=" + qv, qparam);
            } else {
                return url + (url.indexOf("?") == -1 ? "?" : "&") + qparam;
            }
        }
        return url;
    },
    hide: function (o) {
        if (typeof o != "object")
            o = document.getElementById(o);
        if (o) {
            o.style.display = "none";
        }
    },
    tipDialog: function (option) {
        var head = option.head || "提示";
        var content = option.content || "";
        var width = option.width || 200;
        var $overlay = $("<div class='tipDialog-overlay'></div>");
        var $tipDialog = $("<div id='tipDialog'><div class='head'>" + head + "<span class='close-btn'>×</span></div><div class='content'>" + content + "</div></div>");
        $tipDialog.css({
            "width": width + "px",
            "margin": "-100px 0 0 " + (-width / 2) + "px"
        })
        $overlay.appendTo("body");
        $tipDialog.appendTo("body");
        var $clostBtn = $tipDialog.find(".close-btn");
        $clostBtn.click(function () {
            $tipDialog.remove();
            $overlay.remove();
        })
    }
}

$.extend({
    //获取url中的参数
    request: function (name, url) {
        var vars = [], hash;
        var url = url || window.location.href;
        var hashes = url.slice(url.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = decodeURIComponent(hash[1]);
        }
        if (name && name != "") {
            return vars[name];
        } else {
            return vars;
        }
    }
});
/*
异步完成后执行的事件
*/
var AjaxBegin = function (r, a) {
    $("#pagelistId").fadeOut(200, function () {
        var o = $("#pageloading");
        if (o == null || o.length == 0) {
            $("#pagelistId").before('<div id="pageloading" class="pageloading"> <img src="/Resources/img/loading.gif" /> 数据加载....</div>');
        } else {
            $("#pageloading").show();
        }
    });
}

var AjaxSuccess = function (r, a, b, c) {
    
}

var AjaxFailure = function (r, a, b, c) {

}

var AjaxComplete = function (r, a, b, c, d) {
    var fun = function () {
        $('#pagelistId').fadeIn(300);
        $("#pageloading").hide();
    }
    setTimeout(fun, 200);

    var initselect = $("#btn_at_selectAll");
    if (initselect != null && initselect != undefined) {
        $("#btn_at_selectAll").click(function () {
            var chek = $(this).is(":checked");
            var item = $("#pagelistId table tr td input[type='checkbox']");
            var ids = "";
            for (var i = 0; i < item.length; i++) {
                item[i].checked = $(this).is(":checked");
                if (item[i].checked) {
                    ids += item[i].name + ",";
                }
            }
            $("#selectids").val(ids);
        });
        $("#pagelistId table tr td input[type='checkbox']").click(function () {
            var item = $("#pagelistId table tr td input[type='checkbox']");
            var ids = "";
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked) {
                    ids += item[i].name + ",";
                }
            }
            $("#selectids").val(ids);
        });
    }
}

var OnSubmitSuccess = function (o) {
    if (o != null) {
        if (o.success) {
            if (o.url != null && o.url != undefined) {
                window.location.href = o.url;
            }
            else {
                swal({
                    title: "操作提示",
                    text: o.msg,
                    type: "success",
                    closeOnConfirm: true,
                    confirmButtonText: "确定",
                    cancelButtonText: "取消"
                });
            }
        }
        else {
            swal({
                title: "操作提示",
                text: o.msg,
                type: "warning",
                closeOnConfirm: false,
                confirmButtonText: "确定",
                cancelButtonText: "取消"
            });
        }
    }
}

$(function () {
    $("#btnPay").click(function () {
        var custmCode = $("input[name='CustmCode']").val();
        if (!custmCode) {
            swal({
                title: "操作提示",
                text: "请输入商户号",
                type: "warning",
                closeOnConfirm: false,
                confirmButtonText: "确定",
                cancelButtonText: "取消"
            });
            return;
        }
        var money = $("input[name='Money']").val();
        if (!money || money <= 0) {
            swal({
                title: "操作提示",
                text: "金额不正确",
                type: "warning",
                closeOnConfirm: false,
                confirmButtonText: "确定",
                cancelButtonText: "取消"
            });
            return;
        }
        if (money >= 50000) {
            swal({
                title: "操作提示",
                text: "单笔金额不能超过5万",
                type: "warning",
                closeOnConfirm: false,
                confirmButtonText: "确定",
                cancelButtonText: "取消"
            });
            return;
        }
        $("#payform").submit();
        swal({
            title: "操作提示",
            text: "支付处理中...",
            allowOutsideClick: false,
            showConfirmButton: false,
            timer: 10000
        });
    });
});


